﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Fcdbas.WinUI.Controls
{
    public partial class cRichEditControl : DevExpress.XtraEditors.XtraUserControl
    {
        public event EventHandler DocSaveCompleted;
        public event EventHandler DocDeleteCompleted;
        public cRichEditControl()
        {
            InitializeComponent();
        }
        public string ColumnName
        {
            get;
            set;
        }
        private Fcdbas.Core.IEntity _currentEntity;
        public Fcdbas.Core.IEntity CurrentEntity
        {
            get
            {
                return _currentEntity;
            }
            set
            {
                _currentEntity = value;
            }
        }
        private void fileSaveItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            CurrentEntity[ColumnName] = richEditControl.OpenDocumentBytes;
            if (DocSaveCompleted != null)
                DocSaveCompleted(this, EventArgs.Empty);
        }

        private void cRichEditControl_Load(object sender, EventArgs e)
        {
            if (CurrentEntity != null)
            {
                richEditControl.OpenDocumentBytes = (byte[])CurrentEntity[ColumnName];
            }
        }

        private void iClear_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            richEditControl.OpenDocumentBytes = null;
            CurrentEntity[ColumnName] = null;
            if (DocDeleteCompleted != null)
                DocDeleteCompleted(this, EventArgs.Empty);
        }
    }
}
